package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportRemarkLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportRemarkLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-05-18 20:14:27
 */
public class TransportRemarkLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportRemarkLogConverts.class);

    public static List<TransportRemarkLogDTO> convert(List<TransportRemarkLog> transportRemarkLogList) {
        if (CollectionUtils.isEmpty(transportRemarkLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportRemarkLogDTO> transportRemarkLogListResult = Lists.newArrayList();
        for (TransportRemarkLog transportRemarkLog : transportRemarkLogList) {
            transportRemarkLogListResult.add(convert(transportRemarkLog));
        }
        return transportRemarkLogListResult;
    }

    public static TransportRemarkLogDTO convert(TransportRemarkLog transportRemarkLog) {
        try {
            return BeanUtils.copy(transportRemarkLog, TransportRemarkLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportRemarkLog到TransportRemarkLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportRemarkLog到TransportRemarkLogDTO转换失败", e);
        }
    }

    public static TransportRemarkLog convert(TransportRemarkLogDTO transportRemarkLogDTO) {
        try {
            return BeanUtils.copy(transportRemarkLogDTO, TransportRemarkLog.class);
        } catch (Exception e) {
            LOG.error("TransportRemarkLogDTO到TransportRemarkLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportRemarkLogDTO到TransportRemarkLog转换失败", e);
        }
    }
}